package com.winhxd.b2c.order.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.order.condition.*;
import com.winhxd.b2c.common.domain.order.vo.*;
import com.winhxd.b2c.common.feign.order.OrderManagementServiceClient;
import com.winhxd.b2c.common.util.JsonUtil;
import com.winhxd.b2c.order.service.OrderManagementService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author shijinxing
 * @Description 后台管理-订单模块
 * @Date 2019年1月8日10:40:20
 **/
@RestController
public class OrderManagementController implements OrderManagementServiceClient {

    private static final Logger LOGGER = LoggerFactory.getLogger(OrderManagementController.class);

    @Autowired
    private OrderManagementService orderManagementService;

    @Override
    @ApiOperation(value = "订单列表", notes = "订单列表")
    public ResponseResult<PagedList<OrderManagementListVO>> findOrderManagementList(@RequestBody OrderManagementListCondition condition) {
        String logTitle = "/OrderManagementController/findOrderManagementList-后台管理-订单列表";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        ResponseResult<PagedList<OrderManagementListVO>> result = new ResponseResult<>();
        PagedList<OrderManagementListVO> pagedList = new PagedList<>();
        PageHelper.startPage(condition.getPageNo(),condition.getPageSize());
        List<OrderManagementListVO> orderManagementList=orderManagementService.findOrderManagementList(condition);
        PageInfo<OrderManagementListVO> pageInfo = new PageInfo<>(orderManagementList);
        pagedList.setData(pageInfo.getList());
        pagedList.setPageNo(pageInfo.getPageNum());
        pagedList.setPageSize(pageInfo.getPageSize());
        pagedList.setTotalRows(pageInfo.getTotal());
        result.setData(pagedList);
        LOGGER.info("{}=--结束 result={}", logTitle, result);
        return result;
    }

    @Override
    @ApiOperation(value = "发货页面", notes = "发货页面")
    public ResponseResult<OrderDeliverGoodsInfoVO> getDeliverGoodsInfo(@RequestBody OrderDeliverGoodsInfoCondition condition) {
        String logTitle = "/OrderManagementController/getDeliverGoodsInfo-后台管理-发货页面";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        ResponseResult<OrderDeliverGoodsInfoVO> result=new ResponseResult<>();
        OrderDeliverGoodsInfoVO orderDeliverGoodsInfo=orderManagementService.getDeliverGoodsInfo(condition);
        result.setData(orderDeliverGoodsInfo);
        LOGGER.info("{}=--结束 result={}", logTitle, result);
        return result;
    }

    @Override
    @ApiOperation(value = "发货", notes = "发货")
    public ResponseResult<Integer> saveDeliverGoods(@RequestBody OrderDeliverGoodsInfoCondition condition) {
        String logTitle = "/OrderManagementController/saveDeliverGoods-后台管理-发货";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        ResponseResult<Integer> result = new ResponseResult<>();
        Integer integer=orderManagementService.saveDeliverGoods(condition);
        result.setData(integer);
        LOGGER.info("{}=--结束 result={}", logTitle, result);
        return result;
    }


    @Override
    @ApiOperation(value = "购物清单", notes = "购物清单")
    public ResponseResult<OrderShoppingListVO> findShoppingList(@RequestBody OrderShoppingListCondition condition) {
        String logTitle = "/OrderManagementController/findShoppingList-后台管理-购物清单";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        ResponseResult<OrderShoppingListVO> result = new ResponseResult<>();
        OrderShoppingListVO orderShoppingListVO = orderManagementService.findShoppingList(condition);
        result.setData(orderShoppingListVO);
        LOGGER.info("{}=--结束 result={}", logTitle, result);
        return result;
    }

    @Override
    @ApiOperation(value = "配货清单", notes = "配货清单")
    public ResponseResult<OrderDistributionListVO> findDistributionList(@RequestBody OrderDistributionListCondition condition) {
        String logTitle = "/OrderManagementController/findDistributionList-后台管理-配货清单";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        ResponseResult<OrderDistributionListVO> result = new ResponseResult<>();
        OrderDistributionListVO orderDistributionListVO = orderManagementService.findDistributionList(condition);
        result.setData(orderDistributionListVO);
        LOGGER.info("{}=--结束 result={}", logTitle, result);
        return result;
    }

    @Override
    @ApiOperation(value = "订单详情", notes = "订单详情")
    public ResponseResult<OrderManagementDetailsVO> findOrderDetails(@RequestBody OrderDetailsCondition condition) {
        String logTitle = "/OrderManagementController/findOrderDetails-后台管理-订单详情";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        ResponseResult<OrderManagementDetailsVO> result = new ResponseResult<>();
        OrderManagementDetailsVO orderManagementDetailsVO = orderManagementService.findOrderDetails(condition);
        result.setData(orderManagementDetailsVO);
        LOGGER.info("{}=--结束 result={}", logTitle, result);
        return result;
    }

    @Override
    @ApiOperation(value = "关闭订单", notes = "关闭订单")
    public ResponseResult<Integer> modifyOrderStatusToClose(@RequestBody OrderStatusToCloseCondition condition) {
        String logTitle = "/OrderManagementController/modifyOrderStatusToClose-后台管理-关闭订单";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        orderManagementService.modifyOrderStatusToClose(condition);
        ResponseResult<Integer> result = new ResponseResult<>();
        result.setCode(BusinessCode.CODE_OK);
        result.setMessage("修改成功！");
        return result;
    }

    @Override
    @ApiOperation(value = "收退款记录", notes = "收退款记录")
    public ResponseResult<OrderCollectAndRefundRecordVO> findCollectAndRefundRecord(@RequestBody OrderCollectAndRefundRecordCondition condition) {
        String logTitle = "/OrderManagementController/findCollectAndRefundRecord-后台管理-收退款记录";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        ResponseResult<OrderCollectAndRefundRecordVO> result = new ResponseResult<>();
        OrderCollectAndRefundRecordVO orderCollectAndRefundRecordVO = orderManagementService.findCollectAndRefundRecord(condition);
        result.setData(orderCollectAndRefundRecordVO);
        LOGGER.info("{}=--结束 result={}", logTitle, result);
        return result;
    }

    @Override
    @ApiOperation(value = "收发货记录", notes = "收发货记录")
    public ResponseResult<OrderReceivingAndDeliveryRecordVO> findReceivingAndDeliveryRecord(@RequestBody OrderReceivingAndDeliveryRecordCondition condition) {
        String logTitle = "/OrderManagementController/findReceivingAndDeliveryRecord-后台管理-收发货记录";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        ResponseResult<OrderReceivingAndDeliveryRecordVO> result = new ResponseResult<>();
        OrderReceivingAndDeliveryRecordVO orderReceivingAndDeliveryRecordVO = orderManagementService.findReceivingAndDeliveryRecord(condition);
        result.setData(orderReceivingAndDeliveryRecordVO);
        LOGGER.info("{}=--结束 result={}", logTitle, result);
        return result;
    }

    @Override
    @ApiOperation(value = "返利信息", notes = "返利信息")
    public ResponseResult<List<OrderRebateInformationVO>> findRebateInformation(@RequestBody OrderRebateInformationCondition condition) {
        String logTitle = "/OrderManagementController/findRebateInformation-后台管理-返利信息";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        ResponseResult<List<OrderRebateInformationVO>> result = new ResponseResult<>();
        List<OrderRebateInformationVO> orderRebateInformationVO = orderManagementService.findRebateInformation(condition);
        result.setData(orderRebateInformationVO);
        return result;
    }

    @Override
    @ApiOperation(value = "订单日志", notes = "订单日志")
    public ResponseResult<OrderLogVO> findOrderLog(@RequestBody OrderLogCondition condition) {
        String logTitle = "/OrderManagementController/findOrderLog-后台管理-订单日志";
        LOGGER.info("{}=--开始--{}", logTitle, JsonUtil.toJSONString(condition));
        ResponseResult<OrderLogVO> result = new ResponseResult<>();
        OrderLogVO orderLog = orderManagementService.findOrderLog(condition);
        result.setData(orderLog);
        LOGGER.info("{}=--结束 result={}", logTitle, result);
        return result;
    }

}
